package cn.tedu.luban.demand.main.controller;

import cn.tedu.luban.demand.main.converter.DemandConverter;
import cn.tedu.luban.demand.main.service.DemandOrderService;
import cn.tedu.luban.demand.protocol.VO.RequestOrderListItemVO;
import cn.tedu.luban.demand.protocol.bo.RequestOrderBO;
import cn.tedu.luban.demand.protocol.query.RequestOrderQuery;
import com.tedu.inn.protocol.ListRecordTotalBO;
import com.tedu.inn.protocol.exception.BusinessException;
import com.tedu.inn.protocol.model.Result;
import com.tedu.inn.protocol.pager.PagerResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class DemandController {
    /**
     * 通过手机师傅端查询符合要求条件的需求单分页数据
     */
    @Autowired
    private DemandOrderService demandOrderService;

    @Autowired
    private DemandConverter demandConverter;


    @PostMapping("/demand/order/search")
    public Result<PagerResult<RequestOrderListItemVO>> searchRequestOrders(@RequestBody RequestOrderQuery requestOrderQuery) throws BusinessException {
        //1.pageNo，pageSize，list，total，lastIndexPage
        ListRecordTotalBO<RequestOrderBO> bos=demandOrderService.searchRequestOrders(requestOrderQuery);
        //2.转换器转换对象
        PagerResult<RequestOrderListItemVO> requestOrderListItemVOPagerResult = demandConverter.assemblePagerResult(bos,requestOrderQuery);

        return new Result<>(requestOrderListItemVOPagerResult);

    }
}
